package huaweiod.third;

import java.util.*;

/**
 * 告警抑制
 * https://fcqian.blog.csdn.net/article/details/130768150
 */
public class B_AlarmSuppression {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int count = Integer.parseInt(in.nextLine());
        Map<String, Set<String>> map = new HashMap<>();
        for (int i = 0; i < count; i++) {
            String[] s = in.nextLine().split(" ");
            map.putIfAbsent(s[0], new HashSet<>());
            map.get(s[0]).add(s[1]);
        }
        String[] s = in.nextLine().split(" ");
        Set<String> noSelect = new HashSet<>();
        for (int i = 0; i < s.length; i++) {
            if (map.containsKey(s[i])) {
                noSelect.addAll(map.get(s[i]));
            }
        }
        StringJoiner sj = new StringJoiner(" ");
        for (int i = 0; i < s.length; i++) {
            if (!noSelect.contains(s[i])) {
                sj.add(s[i]);
            }
        }
        System.out.println(sj);
    }
}
